home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 34 / Amiga Format CD34 (1998-11-20)(Future Publishing)(GB)[!][Christmas issue].iso / -seriously_amiga- / programming / c / viewperf5.1 / viewperf / clock.c < prev    next >
C/C++ Source or Header  |  1998-10-01  |  2KB  |  81 lines

  1. /*
  2. // Permission to use, copy, modify, and distribute this software and its
  3. // documentation for any purpose and without fee is hereby granted, provided
  4. // that the above copyright notice appear in all copies and that both that
  5. // copyright notice and this permission notice appear in supporting
  6. // documentation, and that the name of I.B.M. not be used in advertising
  7. // or publicity pertaining to distribution of the software without specific,
  8. // written prior permission. I.B.M. makes no representations about the
  9. // suitability of this software for any purpose.  It is provided "as is"
  10. // without express or implied warranty.
  11. //
  12. // I.B.M. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
  13. // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL I.B.M.
  14. // BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  15. // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  16. // OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  17. // CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  18. //
  19. // Author:  Marc Andreessen, Barry Minor, IBM AWS Graphics Systems (Austin)
  20. // Special Thanks to the Men and Women of DEC ...
  21. */
  22.  
  23. #include <stdio.h>
  24. #include <math.h>
  25. #ifdef WIN32
  26. #include <windows.h>
  27. static DWORD gtime;
  28. #elif defined(OS2)
  29. #include <time.h>
  30. #include <stdlib.h>
  31. static int gtime;
  32. #else
  33. #include <sys/types.h>
  34. #include <sys/times.h>
  35. #include <sys/param.h>
  36. #include <time.h>
  37. static struct tms tbuf;
  38. static int gtime;
  39. #endif
  40.  
  41. #include <GL/gl.h>
  42. #include "viewperf.h"
  43.  
  44. float roundit( float number )
  45. {
  46.     /* round number to 3 significant digits */
  47.     char s[15];
  48.     float rounded;
  49.     sprintf(s,"%0.2e", number );
  50.     rounded = (float) atof(s);
  51.     return rounded;
  52. }
  53.  
  54. void startclock (void) 
  55. {
  56. #ifdef WIN32
  57.   gtime = GetTickCount();
  58. #elif defined(OS2)
  59.   gtime = clock();
  60. #else
  61.   gtime = times(&tbuf);
  62. #endif
  63.   
  64.   return;
  65. }
  66.  
  67. float stopclock (void)
  68. {
  69.   float period;
  70.   
  71. #ifdef WIN32
  72.   period = (float)(GetTickCount() - gtime) / 1000.0;
  73. #elif defined(OS2)
  74.   period = (float)(clock() - gtime) / (float)CLK_TCK;
  75. #else
  76.   period = (float)(times(&tbuf) - gtime) / (float)CLK_TCK;
  77. #endif
  78.   return period;
  79. }
  80.  
  81.